VERSION 5.00
Begin VB.Form frmsubreport1 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Select month"
   ClientHeight    =   3165
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   4875
   LinkTopic       =   "Form2"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   3165
   ScaleWidth      =   4875
   Begin VB.CommandButton cmdEstimatedByGindo 
      Caption         =   "Estimated Gindo"
      Height          =   495
      Left            =   5400
      TabIndex        =   10
      Top             =   3240
      Width           =   2415
   End
   Begin VB.CommandButton cmdEstimated 
      Caption         =   "Estimated"
      Height          =   615
      Left            =   5160
      TabIndex        =   9
      Top             =   2160
      Width           =   2055
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Run report"
      Height          =   495
      Left            =   2520
      TabIndex        =   8
      Top             =   1560
      Width           =   1095
   End
   Begin VB.ComboBox cboYear 
      Height          =   315
      Left            =   2595
      TabIndex        =   4
      Top             =   840
      Width           =   975
   End
   Begin VB.ComboBox cboMonth 
      Height          =   315
      Left            =   1515
      TabIndex        =   3
      Top             =   840
      Width           =   615
   End
   Begin VB.ComboBox cboOffice 
      Height          =   315
      Left            =   1515
      TabIndex        =   2
      Text            =   "SGN"
      Top             =   480
      Width           =   2055
   End
   Begin VB.CommandButton Command3 
      Caption         =   "CASH FLOW BY OFFICE"
      Height          =   375
      Left            =   4920
      TabIndex        =   1
      Top             =   600
      Width           =   2655
   End
   Begin VB.CommandButton cmdGindo 
      Caption         =   "CASH FLOW FOR GINDO"
      Height          =   375
      Left            =   5040
      TabIndex        =   0
      Top             =   1080
      Width           =   2655
   End
   Begin VB.Label Label3 
      Alignment       =   1  'Right Justify
      AutoSize        =   -1  'True
      Caption         =   "Year"
      Height          =   195
      Left            =   2160
      TabIndex        =   7
      Top             =   840
      Width           =   330
   End
   Begin VB.Label Label2 
      Alignment       =   1  'Right Justify
      AutoSize        =   -1  'True
      Caption         =   "Month"
      Height          =   195
      Left            =   960
      TabIndex        =   6
      Top             =   840
      Width           =   450
   End
   Begin VB.Label Label1 
      Alignment       =   1  'Right Justify
      AutoSize        =   -1  'True
      Caption         =   "Office"
      Height          =   195
      Left            =   990
      TabIndex        =   5
      Top             =   480
      Width           =   420
   End
End
Attribute VB_Name = "frmsubreport1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
 

Private Sub cmdEstimated_Click()

    Dim ExcelWasNotRunning As Boolean   ' Flag for final release.
    isExportExpenditureForGindo = False
    isNoCloseExcel = False
    DetectExcel
    isFillCheck = 2
    isCreateNewExcel = True
    Call funEstimatedExpenditureREPORT(cboMonth.Text, Right(cboYear.Text, 2), cboOffice.Text, False)
End Sub

Private Sub cmdEstimatedByGindo_Click()
    Dim ExcelWasNotRunning As Boolean   ' Flag for final release.
    isExportExpenditureForGindo = True
    isNoCloseExcel = False
    DetectExcel
    isFillCheck = 2
    isCreateNewExcel = True
    Call funEstimatedExpenditureREPORT(cboMonth.Text, Right(cboYear.Text, 2), cboOffice.Text, True)
End Sub

Private Sub cmdGindo_Click()
    'On Error Resume Next
    Dim previousMMYY As String
    Dim mm, yy As String
    mm = cboMonth.Text
    yy = Right(cboYear.Text, 2)
    If Val(mm) = 1 Then
        previousMMYY = "120" & Val(yy) - 1
    ElseIf Val(mm) - 1 < 10 Then
        previousMMYY = "0" & Val(mm) - 1 & yy
    ElseIf Val(mm) - 1 >= 10 Then
        previousMMYY = Val(mm) - 1 & yy
    End If
    DetectExcel
    'If Not isExistBalance(Left(previousMMYY, 2), Right(previousMMYY, 2), Right(cboOffice.Text, 3)) Then
    '    If MsgBox("The balance of previous month does not exist. Do you want to update the balance manually?(Y/N)", vbQuestion + vbYesNo + vbDefaultButton2, "Update Balance?") = vbNo Then
    '        Exit Sub
    '    Else
    '        frmBalance.Show
    '        frmBalance.cboBMonth.Text = Left(previousMMYY, 2)
    '        frmBalance.cboBYear.Text = "20" & Right(previousMMYY, 2)
    '        Exit Sub
    '    End If
    'End If
    
    Call funCASHFLOWREPORT(cboMonth.Text, Right(cboYear.Text, 2), 1)
End Sub

Private Sub Command1_Click()
    Select Case Command1.Tag
        Case "CF"
            Me.Hide
            Call Command3_Click
        Case "GCF"
            Me.Hide
            Call cmdGindo_Click
        Case "ESTIMATED"
            Me.Hide
            If cboOffice.Text = "GINDO" Then
                Call cmdEstimatedByGindo_Click
            Else
                Call cmdEstimated_Click
            End If
        Case Else
            MsgBox "Unkow"
    End Select
    Unload Me
End Sub

Private Sub Command3_Click()
    'On Error Resume Next
    Dim previousMMYY As String
    Dim mm, yy As String
    mm = cboMonth.Text
    yy = Right(cboYear.Text, 2)
    If Val(mm) = 1 Then
        previousMMYY = "120" & Val(yy) - 1
    ElseIf Val(mm) - 1 < 10 Then
        previousMMYY = "0" & Val(mm) - 1 & yy
    ElseIf Val(mm) - 1 >= 10 Then
        previousMMYY = Val(mm) - 1 & yy
    End If
    DetectExcel
    If Not isExistBalance(Left(previousMMYY, 2), Right(previousMMYY, 2), Right(cboOffice.Text, 3)) Then
        If MsgBox("The balance of previous month does not exist. Do you want to update the balance manually?(Y/N)", vbQuestion + vbYesNo + vbDefaultButton2, "Update Balance?") = vbNo Then
            Exit Sub
        Else
            frmBalance.Show
            frmBalance.cboBMonth.Text = Left(previousMMYY, 2)
            frmBalance.cboBYear.Text = "20" & Right(previousMMYY, 2)
            Exit Sub
        End If
    End If
    TotalExpenditureInCashFlow = 0
    Call funCASHFLOWREPORT(cboMonth.Text, Right(cboYear.Text, 2), 0)
End Sub

Private Sub Form_Load()
    DetectExcel
    Me.Top = Screen.Height / 2 - (Me.Height / 1.5)
        Me.Left = Screen.Width / 2 - (Me.Width / 2)
    Call KetNoi
    
    For i = 1 To 9
        cboMonth.AddItem "0" & i
    Next i
    For i = 10 To 12
        cboMonth.AddItem i
    Next i
    If Month(Now()) < 10 Then
        If Month(Now()) = 1 Then
            cboMonth.Text = "12" '"0" & Month(Now())
        Else
            cboMonth.Text = "0" & Month(Now()) - 1
        End If
    Else
        cboMonth.Text = Month(Now()) - 1
    End If
    For i = 7 To Val(Right(Year(Now()), 2))
        If i < 10 Then
            cboYear.AddItem "200" & i
        Else
            cboYear.AddItem "20" & i
        End If
    Next i
    If Month(Now()) = 1 Then
        cboYear.Text = Year(Now()) - 1
    Else
        cboYear.Text = Year(Now())
    End If
    
    Select Case permit
        Case "A", "B", "G"
            cboOffice.Enabled = True
            cboOffice.AddItem "GHAN"
            cboOffice.AddItem "GSGN"
            'cboOffice.AddItem "GDAD"
            cboOffice.AddItem "GPNH"
            cboOffice.AddItem "GVTE"
            cboOffice.Text = "GINDO"
        Case Else
            cboOffice.AddItem "G" & stroffice
            cboOffice.ListIndex = 0
            cboOffice.Enabled = False
    End Select
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    On Error Resume Next
    ApExcel.Quit
End Sub

Private Sub Form_Terminate()
    On Error Resume Next
    ApExcel.Quit
End Sub

Private Sub Form_Unload(Cancel As Integer)
    On Error Resume Next
    ApExcel.Quit
End Sub

